package com.situ.springboot.service.impl;

import com.situ.springboot.mapper.BlogTypeMapper;
import com.situ.springboot.pojo.entity.BlogType;
import com.situ.springboot.pojo.vo.BlogTypeCountVO;
import com.situ.springboot.service.IBlogTypeService;
import com.situ.springboot.util.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BlogTypeServiceImpl implements IBlogTypeService {

    @Autowired
    private BlogTypeMapper blogTypeMapper;

    //业务
    @Override
    public List<BlogType> selectAll() {
        List<BlogType> list = blogTypeMapper.selectAll();
        return list;
    }

    @Override
    public void deleteById(Integer id) {
        blogTypeMapper.deleteById(id);
    }

    @Override
    public void add(BlogType blogTypeType) {
        blogTypeMapper.add(blogTypeType);
    }

    @Override
    public BlogType selectById(Integer id) {
        return blogTypeMapper.selectById(id);
    }

    @Override
    public void update(BlogType blogTypeType) {
        blogTypeMapper.update(blogTypeType);
    }

    // totalCount:101
    // pageSize:10
    @Override
    public PageInfo selectByPage(Integer pageNo, Integer pageSize) {
        // limit
        int offset = (pageNo - 1) * pageSize;
        //查找当前也数据
        List<BlogType> list = blogTypeMapper.selectByPage(offset, pageSize);
        //查找总的数量，目的是为了算总的页数totalPage
        int totalCount = blogTypeMapper.selectTotalCount();
        int totalPage = (int)Math.ceil((double) totalCount / pageSize);

        return new PageInfo<BlogType>(list, totalPage, pageNo, pageSize);
    }

    @Override
    public void deleteAll(Integer[] ids) {
        blogTypeMapper.deleteAll(ids);
    }

    @Override
    public List<BlogTypeCountVO> selectBlogTypeCount() {
        return blogTypeMapper.selectBlogTypeCount();
    }
}
